/* postcss-simple-vars */
$powerWidth: 30px;
$powerOverlap: 4px; /* must be >= 1px (transparent edge) */

:root {
  --border: 1px solid var(--c80);
  --inner-padding: 18px; /* checkbox + gap */
  --outer-padding: 9px;
  --entry-h: 26px;
  --hotkey-margin: 13px;
  --red1: hsl(0, 70%, 45%);
  --hover: var(--accent-1);
  --hover-icon: var(--c10);
  --hover-disabled: var(--c40);
  scrollbar-width: none; /* suppressing the redundant overall scrollbar */
}
:root.mobile {
  --inner-padding: 25px;
  --entry-h: 36px;
}
[data-ui-theme="dark"] {
  --red1: hsl(0, 85%, 65%);
  --hover: var(--cmin);
  --hover-disabled: var(--c30);
}

html, body {
  overflow: hidden;
}
body {
  width: auto;
  min-width: 246px;
  max-width: 280px;
  display: flex;
  flex-direction: column;
}
#installed-wrapper {
  overflow-y: auto;
}

.firefox button {
  transition: none; /* FF borks subpixel AA during transitions in popup */
}

body > div:not([id=message-box]/*avoiding # to keep specificity low*/):not(.colorpicker-popup) {
  padding-left: var(--outer-padding);
  padding-right: var(--outer-padding);
}

:root:not(.blocked) .if-blocked,
.blocked .if-not-blocked,
.blocked #installed:empty,
.blocked #installed > :not(.frame),
.blocked [data-frame-id="0"] > .breadcrumbs:not(:only-child),
.firefox .chromium-only {
  display: none !important;
}

#main-actions {
  /* raise the actions above the hotkey-info */
  position: relative;
  background: var(--c95);
  z-index: 4;
  padding: 0;
  > * {
    padding: var(--outer-padding);
    display: flex;
  }
  > :nth-last-child(n + 2) {
    flex: 1;
  }
}

:root:not(.blocked) #installed:empty {
  padding: var(--outer-padding);
  background-color: var(--c98);
  flex-flow: column;
  display: flex;
  &::before {
    content: attr(data-no-styles);
  }
  &::after {
    content: attr(data-find);
    font-weight: bold;
  }
  &:hover {
    color: var(--accent-1);
  }
}

.style-name:hover input:is(:checked, *) {
  border-color: var(--c30);
  background-color: var(--c80);
}

#installed {
  counter-reset: style-number;
  position: relative;
  input {
    pointer-events: none;
    color: var(--fg);
    &::after {
      height: auto;
    }
  }
  .actions {
    cursor: default;
  }
  a:hover i {
    color: var(--accent-1);
  }
}

.all-disabled {
  .style-name {
    text-decoration: line-through;
  }
  #disableAll-label {
    &:hover {
      background: hsla(20, 100%, 60%, .1);
    }
    &::after {
      --c: crimson;
      background: var(--c);
      color: #fff;
      font-size: 10px;
      padding: 2px 0;
      left: 0;
      bottom: -9px;
      position: absolute;
      text-align: center;
      text-transform: uppercase;
      width: 100%;
    }
    img {
      right: calc($powerWidth - $powerOverlap);
    }
  }
  #disableAll {
    --color-on: hsla(20, 100%, 60%, .4);
    --shadow-hsl: 348, 83%, 10%;
    color: var(--c);
    justify-content: flex-start;
  }
  #main-actions {
    margin-bottom: 8px;
  }
}
#disableAll-label {
  align-items: center;
  &:hover {
    background: hsla(180, 50%, 40%, .1);
  }
  img {
    position: absolute;
    filter: drop-shadow(1px 1px 2px #0008);
    right: calc(var(--outer-padding) - $powerOverlap);
  }
}
#disableAll {
  --width: $powerWidth;
  margin: 0;
  justify-content: flex-end;
  color: var(--accent-2);
  --color-off: hsla(180, 50%, 40%, .33);
  &::after {
    content: none; /* hiding the knob */
  }
}

.actions a {
  text-decoration: none;
  &:not([href]) {
    cursor: default;
  }
}

/* entry */
.entry {
  position: relative;
}
.blocked-info,
#main-actions,
.styles-last #popup-options,
.styles-first #installed,
.styles-first .entry:nth-last-child(n + 2) {
  border-bottom: var(--border);
}
.styles-last .entry:nth-child(n + 2) {
  border-top: var(--border);
}
.entry-content {
  display: flex;
  box-sizing: border-box;
  height: var(--entry-h);
  &, :root[style] & {
    padding: 0 var(--hotkey-margin) 0 0;
  }
}

.entry .actions {
  display: inline-flex;
  align-items: center;
}
/* not using display:flex to simplify code for ellipsis overflow */
.style-name {
  line-height: var(--entry-h);
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 1px 0 0 var(--outer-padding);
  flex: 1;
}

.disabled .style-name,
.disabled .actions i {
  font-weight: normal;
  color: var(--c60);
}
.disabled:hover a:hover i {
  color: var(--fg);
}

.entry .main-controls {
  display: flex;
  flex: 1;
  overflow: hidden;
  padding-right: 5px;
  align-items: center;
}

.entry:nth-child(-n+10):before {
  counter-increment: style-number;
  content: counter(style-number);
  position: absolute;
  top: 0;
  right: 4px;
  color: var(--c75);
  line-height: var(--entry-h);
}
.entry:nth-child(-n+10):hover:before {
  color: var(--c50);
}
.entry:nth-child(10):before {
  content: "0";
}

html[style*="border"] .entry:nth-child(-n+10):before {
  /* the "show side borders" option adds 2px */
  right: 7px;
}

.entry .actions {
  > :not([hidden]) {
    width: var(--inner-padding);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 2px;
    html.mobile & {
      margin-left: 6px;
    }
  }
  > a.configure {
    padding-right: 2px;
    &[target="_blank"] {
      width: 20px;
    }
  }
}
.menu-button {
  padding-right: 2px;
}
a.configure[target="_blank"] .i-config {
  font-size: var(--icon-font-size);
  margin-top: 1px;
}

.empty .i-empty {
  display: initial;
  color: var(--c50);
  cursor: default;
  pointer-events: auto;
  font-size: 14px;
}
.force-applied {
  .style-name {
    color: var(--accent-2);
  }
  &:hover .style-name {
    color: var(--accent-1);
  }
}
.not-applied {
  .style-name, .actions > * {
    opacity: .25;
    transition: opacity .5s ease-in-out .25s, color .5s ease-in-out .25s;
  }
  .style-name {
    opacity: .5;
  }
  &:hover {
    .style-name, .actions > * {
      opacity: 1;
    }
    .style-name {
      color: var(--red1);
    }
  }
}

/* should be the last of entry to override same-specificity selectors */
.entry:hover :not(i) {
  color: var(--hover);
}
.entry:hover i {
  color: var(--hover-icon);
}
.disabled:hover *:not(i) {
  color: var(--hover-disabled);
}

.frame-url::before {
  content: "iframe: ";
  color: lightslategray;
}

.frame .style-name {
  font-weight: normal;
}

#menu {
  &:not([hidden]) {
    display: flex;
  }
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  align-items: flex-start;
  justify-content: center;
  z-index: 2147483647;
  background-color: rgba(0, 0, 0, 0.4);
  > div {
    background-color: var(--bg);
    border: solid 2px rgba(128, 128, 128, .5);
    max-width: 100%;
  }
  > div > * {
    padding: .75em 1em .5em;
  }
  &:not(.delete) main.delete,
  &.delete main:not(.delete) {
    display: none;
  }
  &.delete {
    > div, [data-cmd=delete] {
      border-color: #c00;
    }
    header {
      background: rgba(255, 0, 0, .25);
    }
  }
  header {
    font-weight: bold;
    background: var(--c90);
    display: flex;
    align-items: center;
    justify-content: space-between;
    a {
      margin-left: 1em;
    }
    i {
      font-size: 20px;
    }
  }
  main {
    > * {
      display: flex;
    }
    > :nth-child(n + 2) {
      padding-top: .5em;
    }
  }
  [data-cmd="delete"]:not([data-focused-via-click]):focus {
    box-shadow: 0 0 0 1px red; /* Using box-shadow instead of the ugly outline in new Chrome */
  }
  .enabled {
    color: var(--accent-1);
  }
  .disabled {
    color: var(--c60);
    cursor: help;
  }
  footer {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: .25em;
    padding-bottom: 1em;
    > * {
      margin: 0 .25em;
    }
  }
  .non-windows & footer {
    direction: rtl;
    justify-content: flex-end;
  }
}

.entry .menu-icon {
  width: 26px;
  flex-shrink: 0;
}

.regexp-problem-indicator {
  background-color: #d00;
  width: 14px;
  height: 14px;
  line-height: 15px;
  border-radius: 8px;
  margin-right: 6px;
  margin-left: 6px;
  text-align: center;
  color: white;
  font-weight: bold;
  box-sizing: border-box;
  cursor: pointer;
  font-size: 90%;
  .entry:not(.regexp-partial) & {
    display: none;
  }
}

:is(.regexp-partial, .regexp-invalid) .actions {
  order: 2;
}

#regexp-explanation {
  position: fixed;
  background-color: var(--bg);
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  right: 0;
  padding: .5rem;
  font-size: 90%;
  border-top: 2px solid var(--fg);
  border-bottom: 2px solid var(--fg);
  box-shadow: 0 0 100px var(--fg);
  display: flex;
  flex-direction: column;
  z-index: 999999;
  > div {
    display: none;
    list-style-type: none;
    padding: 0;
    margin: 0;
    &:not(:last-child) {
      margin-bottom: .5rem;
    }
  }
}

.regexp-partial #regexp-partial,
.regexp-invalid #regexp-invalid {
  display: block;
}

i {
  pointer-events: none;
  font-size: 16px;
}

a:hover i {
  color: var(--fg);
}

/* Never shown, but can be enabled with a style */

.entry .actions > :is(.enable, .disable) {
  display: none;
}

#write-wrapper {
  border-right: var(--border);
}
#write-style-for {
  &::after {
    content: attr(data-text);
  }
  .blocked &::after {
    content: attr(data-blocked);
  }
}
#write-style {
  cursor: pointer;
  overflow: hidden;
  > div {
    transition: opacity .25s .15s;
  }
  &:not(:hover) > div {
    opacity: .5;
  }
}
#write-as {
  flex: 0;
}
#newStyleAsUsercss {
  + i {
    pointer-events: auto;
    margin-left: -1px;
    color: var(--c60);
    cursor: auto;
  }
  &:checked {
    &, & + i {
      border-color: var(--accent-1);
      color: var(--accent-2);
    }
  }
}
[data-ui-theme="dark"] #newStyleAsUsercss:checked {
  border-color: var(--accent-2);
}
.write-style-link {
  text-decoration: none;
  white-space: nowrap;
  &:last-child {
    color: var(--c50);
    overflow: hidden;
    flex: 1 0 1ch;
    text-overflow: ellipsis;
  }
}
.about-blank > .breadcrumbs {
  cursor: default;
}
.match:not([data-frame-id="0"]) a {
  text-decoration: none; /* not underlining iframe links until hovered to reduce visual noise */
}
.match .match {
  margin-left: .5rem;
}
#write-for-frames::before,
.match .match::before {
  content: "";
  width: .4rem;
  height: .4rem;
  margin-left: -.5rem;
  display: block;
  position: absolute;
  border-width: 1px;
  border-style: none none solid solid;
}
.dupe > .breadcrumbs {
  opacity: .5;
}
.dupe:not([data-children]) {
  display: none;
}
#write-for-frames {
  margin: 0 0 -.25em .5rem;
  color: var(--c50);
  transition: color .2s;
  &:hover {
    color: var(--fg);
  }
}
#write-style:not(.expanded) .match:not([data-frame-id="0"]),
#write-style:not(.expanded) .match .match {
  display: none;
}
.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  &:hover a {
    color: var(--c75);
    text-decoration: none
  }
}
/* "dot" after each subdomain name except tld */
[subdomain]:nth-last-child(n + 3)::after {
  content: "."
}
/* :hover style */
.breadcrumbs.url\(\) > a,
/* :hover or :focus on "this URL" sets class="url()" */
.breadcrumbs [subdomain]:is(:hover, :focus),
.breadcrumbs [subdomain]:is(:hover, :focus) ~ [subdomain] {
  color: inherit;
  text-decoration: underline;
}

/* action buttons */

#popup-options {
  --btn-gap: var(--outer-padding);
  display: flex;
  padding: var(--outer-padding);
  margin-right: calc(-1 * var(--btn-gap));
  background: var(--bg);
  justify-content: space-between;
  button:not(:hover) {
    border-color: transparent;
    background: none;
  }
  > * {
    display: flex;
    max-width: calc(50% - var(--btn-gap) - var(--inner-padding));
    margin-right: var(--btn-gap);
  }
}
#options-btn {
  padding: 2px;
  border-radius: 50%;
}
.styles-first:not(.search-results-shown) {
  #popup-options .split-btn-menu {
    bottom: 0;
    transform: translateY(-20px); /* global button style: 13(font) * 1.2(line) + 4(pad) + 2(border) */
  }
  .split-btn-pedal::after {
    border-top: var(--side) solid transparent;
    border-bottom: calc(var(--side) * 1.3) solid currentColor;
    vertical-align: top;
    position: relative;
    top: 1px;
  }
}
.styles-last {
  body {
    display: flex;
    flex-direction: column;
  }
  .blocked-info,
  #installed-wrapper {
    order: 2;
  }
  #main-actions {
    order: 1;
    > :first-child {
      margin-top: 0;
    }
    padding-bottom: var(--outer-padding);
  }
  #search-results {
    order: 3;
  }
  #pct {
    order: -1;
  }
}

.unreachable .entry:not(.frame) {
  opacity: .25;
}
.blocked-info {
  background-color: var(--c98);
  label {
    padding: .75em var(--outer-padding) .5em;
    display: block;
    font-weight: bold;
    margin: 0 calc(-1 * var(--outer-padding)) .5em;
    background-color: var(--bg);
    border-bottom: var(--border);
  }
  p {
    padding: 1px 0 var(--outer-padding);
    margin: 0;
  }
  .copy {
    cursor: copy;
    hyphens: none;
    word-break: break-word;
    font-weight: bold;
    &:hover {
      color: var(--fg);
      text-decoration: underline;
      &:not(.copied) {
        text-decoration-style: dotted;
      }
    }
    i {
      font-size: var(--icon-font-size);
      line-height: var(--font-size);
    }
    &.copied {
      color: var(--accent-1);
    }
  }
}

/******************************************/

#hotkey-info {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--hotkey-margin);
  cursor: help;
  z-index: 1;
  hyphens: auto;

  &:not([data-active]) > * {
    display: none;
  }

  &[data-active] {
    position: fixed;
    left: 6ex;
    bottom: unset;
    width: auto;
    cursor: auto;
    display: flex;
    flex-direction: column;
    border-left: 2px solid var(--bg);
    box-shadow: 0 0 90px rgba(0, 0, 0, .5);
    z-index: 5;
  }

  div {
    padding: 1em;
    border-top: 1px solid var(--c85);
    background-color: var(--bg);
    &:first-child {
      flex-grow: 1;
      padding: 0 1em 1em;
      font-size: 11px;
      overflow-y: auto;
    }
    &:last-child {
      box-shadow: 0 0 90px rgba(0, 0, 0, .25);
      position: relative;
    }
  }

  p {
    text-indent: -3px;
    &:last-child {
      margin-bottom: 0;
    }
  }

  mark {
    display: inline-block;
    color: var(--fg);
    background: linear-gradient(var(--c80), var(--bg));
    padding: 1px 6px 0;
    margin: 2px;
    border: 1px solid var(--bg);
    border-radius: 4px;
    box-shadow: 1px 1px 4px rgba(0, 0, 0, .3);
    font-weight: bold;
    white-space: nowrap;
  }
}

/******************************************/

@media (max-height: 130px) {
  #find-split {
    --menu-pad: .25em;
  }
}
